TESTS=easy_add easy_prod easy_ch easy_lu QR KNN kMeans partitionStrSearch

BINARIES=$(addprefix out/,$(foreach PREFIX,ref_ asan_,$(addprefix ${PREFIX},${TESTS})))

all: ${BINARIES}

all32: ${BINARIES32}

zip32: ${BINARIES32}
	zip ras32_benchmarks.zip ${BINARIES32}	
	
%.ll: %.bc
	llvm-dis $^ -o $@

%.bc: %.c
	clang++ -O1 -emit-llvm -c $^ -o $@
	
FLAGS=-lrt -O3 -fno-omit-frame-pointer -Isrc/include

CLANG=clang++ $(FLAGS)
CLANG_ASAN=$(CLANG) -fsanitize=address


OBJECTS=build/ref_arglib.o
.SECONDARY: ${OBJECTS}

build/ref_%.o: src/%.cpp
	mkdir -p $(dir $@)
	$(CLANG) $^ -c -o $@
build/asan_%.o: src/%.cpp
	mkdir -p $(dir $@)
	$(CLANG_ASAN) $^ -c -o $@
	
# regular binaries with timing output	
out/ref_%: src/%.cpp ${OBJECTS}
	mkdir -p $(dir $@)
	$(CLANG) -g $^ -DENABLE_OUTPUT -o $@
	$(CLANG) $< -S -emit-llvm -c -DENABLE_OUTPUT -o $@.ll
out/asan_%: src/%.cpp ${OBJECTS}
	mkdir -p $(dir $@)
	$(CLANG_ASAN) -g $^ -DENABLE_OUTPUT -o $@
	$(CLANG_ASAN) $< -S -emit-llvm -c -DENABLE_OUTPUT -o $@.ll

.PHONY: clean
clean:
	rm -f out/* build/*
